package com.quyeying.service.impl;

import com.quyeying.entity.TblMessageEntity;
import com.quyeying.mapper.TblMessageDao;
import com.quyeying.service.TblMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.quyeying.utils.result.R;
import com.quyeying.utils.result.ReturnPageData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

/**
* <p>
 *  服务实现类
 * </p>
*
* @author jll
* @since 2022-12-15
*/
@Service
public class TblMessageServiceImpl extends ServiceImpl<TblMessageDao, TblMessageEntity> implements TblMessageService {

    @Override
    public R findListByPage(Integer page, Integer pageCount){
        IPage<TblMessageEntity> wherePage = new Page<>(page, pageCount);
        TblMessageEntity where = new TblMessageEntity();
        IPage<TblMessageEntity> iPage = baseMapper.selectPage(wherePage, Wrappers.query(where));
        return R.success(ReturnPageData.fillingData(iPage));
    }

    @Override
    public R add(TblMessageEntity tblMessageEntity){
        baseMapper.insert(tblMessageEntity);
        return R.success();
    }

    @Override
    public R delete(Long id){
        baseMapper.deleteById(id);
        return R.success();
    }

    @Override
    public R updateData(TblMessageEntity tblMessageEntity){
        baseMapper.updateById(tblMessageEntity);
        return R.success();
    }

    @Override
    public R findById(Long id){
        TblMessageEntity tblMessageEntity = baseMapper.selectById(id);
        return R.success(tblMessageEntity);
    }
}
